module klang.编译.转换.转换_;
import 全局;
import std.functional: ·fd = toDelegate;
import ··类型_ = klang.编译.类型.类型_;
import klang.编译.核心.核心_: 整数_, 创建数组, 返回零值, 映射, 循环每个, 最小, 获取正规文件名函数_, 查找索引, 结尾包含;
import klang.编译.类型.枚举值.枚举值_: 节点标志_, SK;
import klang.编译.类型.类型_: 输出结果_, 写文件回调_, 输出解析器_, 定制转换组_, 输出转换组_, 转换工厂_, 转换上下文_, 转换函数_, 前端接口_, 程序主机接口_, TransformationResult, LexicalEnvironmentFlags, OnSubstituteNode_, OnEmitNode_, EmitHint;
import klang.编译.诊断.诊断_: 诊断_;
import klang.编译.语法节点.节点_: 节点_, 源文件_;
import klang.编译.工具.工具_: 获取节点的源文件, getParseTreeNode_1;
import klang.编译.输出节点.输出节点_: disposeEmitNodes, getEmitFlags, EmitFlags, setEmitFlags;
import klang.编译.路径.路径_: 获取正规化路径组件组, 获取路径从路径组件组, 获取正规化绝对路径, 组合路径, 文件扩展名是, 获取相对路径从目录, 相对路径, 目录分割符;
enum TransformationState : int {
    Uninitialized = 0,
    Initialized = 1,
    Completed = 2,
    Disposed = 3
}
enum SyntaxKindFeatureFlags : int {
    无_ = 0,
    Substitution = 1,
    EmitNotifications = 2
}
struct 未完成的_ {
    long 开始位置;
    节点_[] 未完成组;
    this(long 位置, 节点_[] ns) {
        this.开始位置 = 位置;
        this.未完成组 = ns;
    }
}
输出转换组_ getTransformers(前端接口_ host) {
    return host.getTransformers();
}
节点_ noEmitSubstitution(EmitHint _hint, 节点_ node) {
    return node;
}
void noEmitNotification(EmitHint hint, 节点_ node, void delegate(EmitHint, 节点_) callback) {
    callback(hint, node);
}
TransformationResult transformNodes(输出解析器_ resolver, 节点_[] nodes, 转换工厂_!(节点_)[] transformers) {
    节点_[] delegate(节点_) transformation;
    void delegate(long) enableSubstitution;
    void delegate(long) enableEmitNotification;
    void delegate(LexicalEnvironmentFlags, bool) setLexicalEnvironmentFlags;
    LexicalEnvironmentFlags delegate() getLexicalEnvironmentFlags;
    bool delegate(节点_) isSubstitutionEnabled;
    节点_ delegate(EmitHint, 节点_) substituteNode;
    bool delegate(节点_) isEmitNotificationEnabled;
    void delegate(EmitHint, 节点_, void delegate(EmitHint, 节点_)) emitNodeWithNotification;
    void delegate() dispose;
    void delegate(节点_) hoistVariableDeclaration;
    void delegate(节点_) hoistFunctionDeclaration;
    void delegate(节点_) addInitializationStatement;
    void delegate() startLexicalEnvironment;
    void delegate() suspendLexicalEnvironment;
    void delegate() resumeLexicalEnvironment;
    节点_[] delegate(节点_ delegate(节点_[])) endLexicalEnvironment;
    void delegate() startBlockScope;
    节点_[] delegate(节点_ delegate(节点_)) endBlockScope;
    void delegate(节点_) addBlockScopedVariable;
    SyntaxKindFeatureFlags[] enabledSyntaxKindFeatures;
    节点_[] lexicalEnvironmentVariableDeclarations;
    节点_[] lexicalEnvironmentFunctionDeclarations;
    节点_[] lexicalEnvironmentStatements;
    LexicalEnvironmentFlags lexicalEnvironmentFlags;
    节点_[][] lexicalEnvironmentVariableDeclarationsStack;
    节点_[][] lexicalEnvironmentFunctionDeclarationsStack;
    节点_[][] lexicalEnvironmentStatementsStack;
    LexicalEnvironmentFlags[] lexicalEnvironmentFlagsStack;
    long lexicalEnvironmentStackOffset;
    bool lexicalEnvironmentSuspended;
    节点_[][] blockScopedVariableDeclarationsStack;
    long blockScopeStackOffset;
    节点_[] blockScopedVariableDeclarations;
    int state;
    诊断_[] diagnostics;
    程序主机接口_ 主机;
    ··类型_.编译选项基类_ 选项;
    转换上下文_ context;
    转换函数_!(节点_)[] transformersWithContext;
    节点_[] transformed;
    TransformationResult 结果;
    节点_[] transformation·func(节点_ node) {
        节点_ delegate(节点_, long) 内部转换;
        未完成的_[] 未完成的组;
        节点_ 结果节点;
        节点_[] 结果;
        节点_ 内部转换·func(节点_ n, long i) {
            for (; i < transformersWithContext.length; ++i) {
                转换函数_!(节点_) transform = transformersWithContext[i];
                节点_[] narr = transform(n);
                if (narr !is ··null!(节点_[])) {
                    if (narr.length > 1) {
                        n = narr[0];
                        未完成的_ 当前未完成的 = .未完成的_(i, narr[1 .. $]);
                        .追加!(未完成的_)(未完成的组, 当前未完成的);
                    }
                    else {
                        n = narr[0];
                    }
                }
            }
            return n;
        }
        内部转换 = &内部转换·func;
        未完成的组 = 创建数组!(未完成的_)();
        结果节点 = 内部转换(node, 0);
        结果 = 创建数组!(节点_)();
        if ((结果节点.标志 & 节点标志_.不输出文件) == 0) {
            .追加!(节点_)(结果, 结果节点);
        }
        while(未完成的组.length > 0) {
            未完成的_ 第一个 = 未完成的组[0];
            节点_ 第一个节点 = 第一个.未完成组[0];
            未完成的组[0].未完成组 = 第一个.未完成组[1 .. $];
            节点_ 第一个结果 = 内部转换(第一个节点, 第一个.开始位置 + 1);
            if (未完成的组[0].未完成组.length == 0) {
                未完成的组 = 未完成的组[1 .. $];
            }
            if ((第一个结果.标志 & 节点标志_.不输出文件) == 0) {
                .追加!(节点_)(结果, 第一个结果);
            }
        }
        if (结果.length > 0) {
            return 结果;
        }
        return ··null!(节点_[]);
    }
    transformation = &transformation·func;
    /**
     * Enables expression substitutions in the pretty printer for the provided KSK.
     */
    void enableSubstitution·func(long kind) {
        assert(state < TransformationState.Completed, "Cannot modify the transformation context after transformation has completed."c);
        if (enabledSyntaxKindFeatures.length <= kind) {
            enabledSyntaxKindFeatures.length = kind + 10;
        }
        enabledSyntaxKindFeatures[kind] |= SyntaxKindFeatureFlags.Substitution;
    }
    enableSubstitution = &enableSubstitution·func;
    /**
     * Enables before/after emit notifications in the pretty printer for the provided KSK.
     */
    void enableEmitNotification·func(long kind) {
        assert(state < TransformationState.Completed, "Cannot modify the transformation context after transformation has completed."c);
        if (enabledSyntaxKindFeatures.length <= kind) {
            enabledSyntaxKindFeatures.length = kind + 10;
        }
        enabledSyntaxKindFeatures[kind] |= SyntaxKindFeatureFlags.EmitNotifications;
    }
    enableEmitNotification = &enableEmitNotification·func;
    void setLexicalEnvironmentFlags·func(LexicalEnvironmentFlags flags, bool value) {
        lexicalEnvironmentFlags = value ? lexicalEnvironmentFlags | flags : lexicalEnvironmentFlags & ~flags;
    }
    setLexicalEnvironmentFlags = &setLexicalEnvironmentFlags·func;
    LexicalEnvironmentFlags getLexicalEnvironmentFlags·func() {
        return lexicalEnvironmentFlags;
    }
    getLexicalEnvironmentFlags = &getLexicalEnvironmentFlags·func;
    /**
     * Determines whether expression substitutions are enabled for the provided node.
     */
    bool isSubstitutionEnabled·func(节点_ node) {
        if (enabledSyntaxKindFeatures.length <= node.目标种类) {
            return false;
        }
        return (enabledSyntaxKindFeatures[node.目标种类] & SyntaxKindFeatureFlags.Substitution) != SyntaxKindFeatureFlags.无_ && (getEmitFlags(node) & EmitFlags.NoSubstitution) == EmitFlags.None;
    }
    isSubstitutionEnabled = &isSubstitutionEnabled·func;
    /**
     * Emits a node with possible substitution.
     *
     * @param hint A hint as to the intended usage of the node.
     * @param node The node to emit.
     * @param emitCallback The callback used to emit the node or its substitute.
     */
    节点_ substituteNode·func(EmitHint hint, 节点_ node) {
        assert(state < TransformationState.Disposed, "Cannot substitute a node after the result is disposed."c);
        if (node !is ··null!(节点_)) {
            if (isSubstitutionEnabled(node)) {
                节点_ n = context.onSubstituteNode(hint, node);
                if (n !is ··null!(节点_)) {
                    return n;
                }
            }
        }
        return node;
    }
    substituteNode = &substituteNode·func;
    /**
     * Determines whether before/after emit notifications should be raised in the pretty
     * printer when it emits a node.
     */
    bool isEmitNotificationEnabled·func(节点_ node) {
        if (enabledSyntaxKindFeatures.length <= node.目标种类) {
            return false;
        }
        return (enabledSyntaxKindFeatures[node.目标种类] & SyntaxKindFeatureFlags.EmitNotifications) != SyntaxKindFeatureFlags.无_ || (getEmitFlags(node) & EmitFlags.AdviseOnEmitNode) != EmitFlags.None;
    }
    isEmitNotificationEnabled = &isEmitNotificationEnabled·func;
    /**
     * Emits a node with possible emit notification.
     *
     * @param hint A hint as to the intended usage of the node.
     * @param node The node to emit.
     * @param emitCallback The callback used to emit the node.
     */
    void emitNodeWithNotification·func(EmitHint hint, 节点_ node, void delegate(EmitHint, 节点_) emitCallback) {
        assert(state < TransformationState.Disposed, "Cannot invoke TransformationResult callbacks after the result is disposed."c);
        if (node !is ··null!(节点_)) {
            if (isEmitNotificationEnabled(node)) {
                context.onEmitNode(hint, node, cast(void delegate(EmitHint, 节点_))(emitCallback));
            }
            else {
                emitCallback(hint, node);
            }
        }
    }
    emitNodeWithNotification = &emitNodeWithNotification·func;
    void dispose·func() {
        if (state < TransformationState.Disposed) {
            // Clean up emit nodes on parse tree
            foreach (节点_ n; nodes) {
                节点_ 节点 = getParseTreeNode_1(n);
                if (节点 !is ··null!(节点_)) {
                    源文件_ sou = 获取节点的源文件(节点);
                    if (sou !is ··null!(源文件_)) {
                        disposeEmitNodes(sou);
                    }
                }
            }
            // Release references to external entries for GC purposes.
            lexicalEnvironmentVariableDeclarations = 返回零值!(节点_[])();
            lexicalEnvironmentVariableDeclarationsStack = 返回零值!(节点_[][])();
            lexicalEnvironmentFunctionDeclarations = 返回零值!(节点_[])();
            lexicalEnvironmentFunctionDeclarationsStack = 返回零值!(节点_[][])();
            // Prevent further use of the transformation result.
            state = TransformationState.Disposed;
        }
    }
    dispose = &dispose·func;
    void hoistVariableDeclaration·func(节点_ decl) {
        assert(state > TransformationState.Uninitialized, "Cannot modify the lexical environment during initialization."c);
        assert(state < TransformationState.Completed, "Cannot modify the lexical environment after transformation has completed."c);
        if (lexicalEnvironmentVariableDeclarations is ··null!(节点_[])) {
            lexicalEnvironmentVariableDeclarations = 创建数组!(节点_)(); // [decl];
            .追加!(节点_)(lexicalEnvironmentVariableDeclarations, decl);
        }
        else {
            .追加!(节点_)(lexicalEnvironmentVariableDeclarations, decl);
        }
        if ((lexicalEnvironmentFlags & LexicalEnvironmentFlags.InParameters) != 0) {
            lexicalEnvironmentFlags |= LexicalEnvironmentFlags.VariablesHoistedInParameters;
        }
    }
    hoistVariableDeclaration = &hoistVariableDeclaration·func;
    /**
     *  Records a hoisted 函数 declaration within a lexical environment.
     */
    void hoistFunctionDeclaration·func(节点_ func) {
        assert(state > TransformationState.Uninitialized, "Cannot modify the lexical environment during initialization."c);
        assert(state < TransformationState.Completed, "Cannot modify the lexical environment after transformation has completed."c);
        setEmitFlags!(节点_)(func, EmitFlags.CustomPrologue);
        if (lexicalEnvironmentFunctionDeclarations is ··null!(节点_[])) {
            lexicalEnvironmentFunctionDeclarations = 创建数组!(节点_)();
            .追加!(节点_)(lexicalEnvironmentFunctionDeclarations, func);
        }
        else {
            .追加!(节点_)(lexicalEnvironmentFunctionDeclarations, func);
        }
    }
    hoistFunctionDeclaration = &hoistFunctionDeclaration·func;
    /**
     * Adds an initialization statement to the top of the lexical environment.
     */
    void addInitializationStatement·func(节点_ node) {
        assert(state > TransformationState.Uninitialized, "Cannot modify the lexical environment during initialization."c);
        assert(state < TransformationState.Completed, "Cannot modify the lexical environment after transformation has completed."c);
        setEmitFlags!(节点_)(node, EmitFlags.CustomPrologue);
        if (lexicalEnvironmentStatements is ··null!(节点_[])) {
            lexicalEnvironmentStatements = 创建数组!(节点_)();
            .追加!(节点_)(lexicalEnvironmentStatements, node);
        }
        else {
            .追加!(节点_)(lexicalEnvironmentStatements, node);
        }
    }
    addInitializationStatement = &addInitializationStatement·func;
    /**
     * Starts a new lexical environment. Any existing hoisted variable or 函数 declarations
     * are pushed onto a stack, and the related storage variables are reset.
     */
    void startLexicalEnvironment·func() {
        assert(state > TransformationState.Uninitialized, "Cannot modify the lexical environment during initialization."c);
        assert(state < TransformationState.Completed, "Cannot modify the lexical environment after transformation has completed."c);
        assert(!lexicalEnvironmentSuspended, "Lexical environment is suspended."c);
        // Save the current lexical environment. Rather than resizing the array we adjust the
        // stack size variable. This allows us to reuse existing array slots we've
        // already allocated between transformations to avoid allocation and GC overhead during
        // transformation.
        if (lexicalEnvironmentVariableDeclarationsStack.length < lexicalEnvironmentStackOffset - 1) {
            lexicalEnvironmentVariableDeclarationsStack.length += 10;
        }
        lexicalEnvironmentVariableDeclarationsStack[lexicalEnvironmentStackOffset] = lexicalEnvironmentVariableDeclarations;
        if (lexicalEnvironmentFunctionDeclarationsStack.length < lexicalEnvironmentStackOffset - 1) {
            lexicalEnvironmentFunctionDeclarationsStack.length += 10;
        }
        lexicalEnvironmentFunctionDeclarationsStack[lexicalEnvironmentStackOffset] = lexicalEnvironmentFunctionDeclarations;
        if (lexicalEnvironmentStatementsStack.length < lexicalEnvironmentStackOffset - 1) {
            lexicalEnvironmentStatementsStack.length += 10;
        }
        lexicalEnvironmentStatementsStack[lexicalEnvironmentStackOffset] = lexicalEnvironmentStatements;
        if (lexicalEnvironmentFlagsStack.length < lexicalEnvironmentStackOffset - 1) {
            lexicalEnvironmentFlagsStack.length += 10;
        }
        lexicalEnvironmentFlagsStack[lexicalEnvironmentStackOffset] = lexicalEnvironmentFlags;
        ++lexicalEnvironmentStackOffset;
        lexicalEnvironmentVariableDeclarations = 返回零值!(节点_[])();
        lexicalEnvironmentFunctionDeclarations = 返回零值!(节点_[])();
        lexicalEnvironmentStatements = 返回零值!(节点_[])();
        lexicalEnvironmentFlags = LexicalEnvironmentFlags.None;
    }
    startLexicalEnvironment = &startLexicalEnvironment·func;
    /** Suspends the current lexical environment, usually after visiting a parameter list. */
    void suspendLexicalEnvironment·func() {
        assert(state > TransformationState.Uninitialized, "Cannot modify the lexical environment during initialization."c);
        assert(state < TransformationState.Completed, "Cannot modify the lexical environment after transformation has completed."c);
        assert(!lexicalEnvironmentSuspended, "Lexical environment is already suspended."c);
        lexicalEnvironmentSuspended = true;
    }
    suspendLexicalEnvironment = &suspendLexicalEnvironment·func;
    /** Resumes a suspended lexical environment, usually before visiting a 函数 body. */
    void resumeLexicalEnvironment·func() {
        assert(state > TransformationState.Uninitialized, "Cannot modify the lexical environment during initialization."c);
        assert(state < TransformationState.Completed, "Cannot modify the lexical environment after transformation has completed."c);
        assert(lexicalEnvironmentSuspended, "Lexical environment is not suspended."c);
        lexicalEnvironmentSuspended = false;
    }
    resumeLexicalEnvironment = &resumeLexicalEnvironment·func;
    /**
     * Ends a lexical environment. The previous set of hoisted declarations are restored and
     * any hoisted declarations added in this environment are returned.
     */
    节点_[] endLexicalEnvironment·func(节点_ delegate(节点_[]) fn) {
        节点_[] statements;
        assert(state > TransformationState.Uninitialized, "Cannot modify the lexical environment during initialization."c);
        assert(state < TransformationState.Completed, "Cannot modify the lexical environment after transformation has completed."c);
        assert(!lexicalEnvironmentSuspended, "Lexical environment is suspended."c);
        if ((lexicalEnvironmentVariableDeclarations !is ··null!(节点_[])) || (lexicalEnvironmentFunctionDeclarations !is ··null!(节点_[])) || (lexicalEnvironmentStatements !is ··null!(节点_[]))) {
            if (lexicalEnvironmentFunctionDeclarations !is ··null!(节点_[])) {
                statements = 创建数组!(节点_)();
                .追加!(节点_)(statements, lexicalEnvironmentFunctionDeclarations);
            }
            if (lexicalEnvironmentVariableDeclarations !is ··null!(节点_[])) {
                节点_ statement = fn(lexicalEnvironmentVariableDeclarations);
                setEmitFlags!(节点_)(statement, EmitFlags.CustomPrologue);
                if (statements is ··null!(节点_[])) {
                    statements = 创建数组!(节点_)(); // [statement];
                    .追加!(节点_)(statements, statement);
                }
                else {
                    //statements.push(statement);
                    .追加!(节点_)(statements, statement);
                }
            }
            if (lexicalEnvironmentStatements !is ··null!(节点_[])) {
                if (statements is ··null!(节点_[])) {
                    statements = 创建数组!(节点_)();
                    .追加!(节点_)(statements, lexicalEnvironmentStatements);
                }
                else {
                    .追加!(节点_)(statements, lexicalEnvironmentStatements);
                }
            }
        }
        // Restore the previous lexical environment.
        --lexicalEnvironmentStackOffset;
        lexicalEnvironmentVariableDeclarations = lexicalEnvironmentVariableDeclarationsStack[lexicalEnvironmentStackOffset];
        lexicalEnvironmentFunctionDeclarations = lexicalEnvironmentFunctionDeclarationsStack[lexicalEnvironmentStackOffset];
        lexicalEnvironmentStatements = lexicalEnvironmentStatementsStack[lexicalEnvironmentStackOffset];
        lexicalEnvironmentFlags = lexicalEnvironmentFlagsStack[lexicalEnvironmentStackOffset];
        if (lexicalEnvironmentStackOffset == 0) {
            lexicalEnvironmentVariableDeclarationsStack = [];
            lexicalEnvironmentFunctionDeclarationsStack = [];
            lexicalEnvironmentStatementsStack = [];
            lexicalEnvironmentFlagsStack = [];
        }
        return statements;
    }
    endLexicalEnvironment = &endLexicalEnvironment·func;
    /**
     * Starts a block scope. Any existing block hoisted variables are pushed onto the stack and the related storage variables are reset.
     */
    void startBlockScope·func() {
        assert(state > TransformationState.Uninitialized, "Cannot start a block scope during initialization."c);
        assert(state < TransformationState.Completed, "Cannot start a block scope after transformation has completed."c);
        if (blockScopedVariableDeclarationsStack.length < blockScopeStackOffset - 1) {
            blockScopedVariableDeclarationsStack.length += 10;
        }
        blockScopedVariableDeclarationsStack[blockScopeStackOffset] = blockScopedVariableDeclarations;
        ++blockScopeStackOffset;
        blockScopedVariableDeclarations = 返回零值!(节点_[])();
    }
    startBlockScope = &startBlockScope·func;
    /**
     * Ends a block scope. The previous set of block hoisted variables are restored. Any hoisted declarations are returned.
     */
    节点_[] endBlockScope·func(节点_ delegate(节点_) fn) {
        节点_[] statements;
        assert(state > TransformationState.Uninitialized, "Cannot end a block scope during initialization."c);
        assert(state < TransformationState.Completed, "Cannot end a block scope after transformation has completed."c);
        if ((blockScopedVariableDeclarations !is ··null!(节点_[])) && blockScopedVariableDeclarations.length > 0) {
            节点_[] 声明组 = 映射!(节点_, 节点_)(blockScopedVariableDeclarations, (节点_ n, size_t _) { return fn(n); });
            if (statements is ··null!(节点_[])) {
                statements = 创建数组!(节点_)();
            }
            .追加!(节点_)(statements, 声明组);
        }
        --blockScopeStackOffset;
        blockScopedVariableDeclarations = blockScopedVariableDeclarationsStack[blockScopeStackOffset];
        if (blockScopeStackOffset == 0) {
            blockScopedVariableDeclarationsStack = [];
        }
        return statements;
    }
    endBlockScope = &endBlockScope·func;
    void addBlockScopedVariable·func(节点_ name) {
        assert(blockScopeStackOffset > 0, "Cannot add a block scoped variable outside of an iteration body."c);
        if (blockScopedVariableDeclarations is ··null!(节点_[])) {
            blockScopedVariableDeclarations = 创建数组!(节点_)();
        }
        .追加!(节点_)(blockScopedVariableDeclarations, name);
    }
    addBlockScopedVariable = &addBlockScopedVariable·func;
    if ((transformers is ··null!(转换工厂_!(节点_)[])) || transformers.length == 0) {
        return ··null!(TransformationResult);
    }
    enabledSyntaxKindFeatures = 创建数组!(SyntaxKindFeatureFlags)();
    lexicalEnvironmentFlags = LexicalEnvironmentFlags.None;
    lexicalEnvironmentVariableDeclarationsStack = 创建数组!(节点_[])();
    lexicalEnvironmentFunctionDeclarationsStack = 创建数组!(节点_[])();
    lexicalEnvironmentStatementsStack = 创建数组!(节点_[])();
    lexicalEnvironmentFlagsStack = 创建数组!(LexicalEnvironmentFlags)();
    lexicalEnvironmentStackOffset = 0;
    lexicalEnvironmentSuspended = false;
    blockScopedVariableDeclarationsStack = 创建数组!(节点_[])();
    blockScopeStackOffset = 0;
    blockScopedVariableDeclarations = 创建数组!(节点_)();
    state = TransformationState.Uninitialized;
    diagnostics = 创建数组!(诊断_)();
    主机 = resolver.获取主机();
    选项 = 主机.获取编译选项();
    context.getCompilerOptions = () { return 选项; };
    context.getEmitResolver = () { return resolver; }; // TODO: GH#18217
    context.getEmitHost = () { return 主机; }; // TODO: GH#18217
    context.startLexicalEnvironment = () { return startLexicalEnvironment(); };
    context.suspendLexicalEnvironment = () { return suspendLexicalEnvironment(); };
    context.resumeLexicalEnvironment = () { return resumeLexicalEnvironment(); };
    context.endLexicalEnvironment = (节点_ delegate(节点_[]) fn) { return endLexicalEnvironment(cast(节点_ delegate(节点_[]))(fn)); };
    context.setLexicalEnvironmentFlags = (LexicalEnvironmentFlags flags, bool value) { return setLexicalEnvironmentFlags(flags, value); };
    context.getLexicalEnvironmentFlags = () { return getLexicalEnvironmentFlags(); };
    context.hoistVariableDeclaration = (节点_ node) { return hoistVariableDeclaration(node); };
    context.hoistFunctionDeclaration = (节点_ functionDeclaration) { return hoistFunctionDeclaration(functionDeclaration); };
    context.addInitializationStatement = (节点_ node) { return addInitializationStatement(node); };
    context.startBlockScope = () { return startBlockScope(); };
    context.endBlockScope = (节点_ delegate(节点_) fn) { return endBlockScope(cast(节点_ delegate(节点_))(fn)); };
    context.addBlockScopedVariable = (节点_ node) { return addBlockScopedVariable(node); };
    context.enableSubstitution = (整数_ kind) { return enableSubstitution(kind); };
    context.enableEmitNotification = (整数_ kind) { return enableEmitNotification(kind); };
    context.isSubstitutionEnabled = (节点_ node) { return isSubstitutionEnabled(node); };
    context.isEmitNotificationEnabled = (节点_ node) { return isEmitNotificationEnabled(node); };
    context.enabledSyntaxKindFeaturesRe = () { enabledSyntaxKindFeatures = 创建数组!(SyntaxKindFeatureFlags)(); };
    context.onSubstituteNode = cast(OnSubstituteNode_)(·fd(&.noEmitSubstitution));
    context.onEmitNode = cast(OnEmitNode_)(·fd(&.noEmitNotification));
    foreach (节点_ n; nodes) {
        节点_ 节点 = getParseTreeNode_1(n);
        if (节点 !is ··null!(节点_)) {
            源文件_ sou = 获取节点的源文件(节点);
            if (sou !is ··null!(源文件_)) {
                disposeEmitNodes(sou);
            }
        }
    }
    transformersWithContext = 映射!(转换工厂_!(节点_), 转换函数_!(节点_))(transformers, (转换工厂_!(节点_) t, size_t _) { return t(context); });
    transformed = 创建数组!(节点_)();
    {
        for (int i = 0; i < nodes.length; ++i) {
            节点_ n;
            节点_[] 转换的;
            n = nodes[i];
            if (i == nodes.length - 1) {
                n.标志 |= (cast(整数_)(节点标志_.节点组中最后一个));
            }
            转换的 = transformation(n);
            if (转换的 !is ··null!(节点_[])) {
                .追加!(节点_)(transformed, 转换的);
            }
        }
    }
    结果.transformed = transformed;
    结果.substituteNode = (EmitHint hint, 节点_ node) { return substituteNode(hint, node); };
    结果.emitNodeWithNotification = (EmitHint hint, 节点_ node, void delegate(EmitHint, 节点_) emitCallback) { return emitNodeWithNotification(hint, node, cast(void delegate(EmitHint, 节点_))(emitCallback)); };
    结果.isEmitNotificationEnabled = (节点_ node) { return isEmitNotificationEnabled(node); };
    结果.dispose = () { return dispose(); };
    结果.diagnostics = diagnostics;
    return 结果;
}
